package com.hspedu.newData.dmsxl.滑动窗口;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC1004最大连续1的个数Ⅲ {

    public int longestOnes(int[] nums, int k) {
        int slow = 0;
        int count = 0;
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0){
                count++;
            }
            while(count > k){
                if (nums[slow++] == 0){
                    count--;
                }
            }
            max = Math.max(max,i-slow + 1);
        }
        return max;
    }


    @Test
    public void test() {
        // 测试代码

        longestOnes(new int[]{1,1,1,0,0,0,1,1,1,1,0},2);
        longestOnes(new int[]{0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1},3);
    }
}
